package com.ruoyi.jiajia.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.JiajiaMessage;
import com.ruoyi.system.service.IJiajiaMessageService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 消息后台Controller
 * 
 * @author knd
 * @date 2021-10-15
 */
@Controller
@RequestMapping("/jiajia/jiaJiaMessage")
public class JiajiaMessageController extends BaseController
{
    private String prefix = "jiajia/jiaJiaMessage";

    @Autowired
    private IJiajiaMessageService jiajiaMessageService;

    @RequiresPermissions("jiajia:jiaJiaMessage:view")
    @GetMapping()
    public String jiaJiaMessage()
    {
        return prefix + "/jiaJiaMessage";
    }

    /**
     * 查询消息后台列表
     */
    @RequiresPermissions("jiajia:jiaJiaMessage:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(JiajiaMessage jiajiaMessage)
    {
        startPage();
        List<JiajiaMessage> list = jiajiaMessageService.selectJiajiaMessageList(jiajiaMessage);
        return getDataTable(list);
    }

    /**
     * 导出消息后台列表
     */
    @RequiresPermissions("jiajia:jiaJiaMessage:export")
    @Log(title = "消息后台", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(JiajiaMessage jiajiaMessage)
    {
        List<JiajiaMessage> list = jiajiaMessageService.selectJiajiaMessageList(jiajiaMessage);
        ExcelUtil<JiajiaMessage> util = new ExcelUtil<JiajiaMessage>(JiajiaMessage.class);
        return util.exportExcel(list, "消息后台数据");
    }

    /**
     * 新增消息后台
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存消息后台
     */
    @RequiresPermissions("jiajia:jiaJiaMessage:add")
    @Log(title = "消息后台", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(JiajiaMessage jiajiaMessage)
    {
        return toAjax(jiajiaMessageService.insertJiajiaMessage(jiajiaMessage));
    }

    /**
     * 修改消息后台
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        JiajiaMessage jiajiaMessage = jiajiaMessageService.selectJiajiaMessageById(id);
        mmap.put("jiajiaMessage", jiajiaMessage);
        return prefix + "/edit";
    }

    /**
     * 修改保存消息后台
     */
    @RequiresPermissions("jiajia:jiaJiaMessage:edit")
    @Log(title = "消息后台", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(JiajiaMessage jiajiaMessage)
    {
        return toAjax(jiajiaMessageService.updateJiajiaMessage(jiajiaMessage));
    }

    /**
     * 删除消息后台
     */
    @RequiresPermissions("jiajia:jiaJiaMessage:remove")
    @Log(title = "消息后台", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(jiajiaMessageService.deleteJiajiaMessageByIds(ids));
    }
}
